package br.edu.com1263.dao;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class Connection {
	private static Connection instance;
	private String persistenceUnit;
	private EntityManagerFactory factory;
	private EntityManager manager;

	private Connection(String persistenceUnit) {
		this.persistenceUnit = persistenceUnit;
		createSession();
	}

	public static Connection getInstance() {
		if (instance == null) {
			instance = new Connection("com1263");
		}
		return instance;
	}

	public void createSession() {
		factory = Persistence.createEntityManagerFactory(persistenceUnit);
		manager = factory.createEntityManager();
	}

	public void destroySession() {
	}

	public EntityManagerFactory getFactory() {
		return factory;
	}

	public void setFactory(EntityManagerFactory factory) {
		this.factory = factory;
	}

	public EntityManager getManager() {
		return manager;
	}

	public void setManager(EntityManager manager) {
		this.manager = manager;
	}

	public String getPersistenceUnit() {
		return persistenceUnit;
	}

	public void setPersistenceUnit(String persistenceUnit) {
		this.persistenceUnit = persistenceUnit;
	}

}
